package websphinx;


public class MatchCloseTag implements MatchAction {

	private String tagName = null;

	public MatchCloseTag(String name) {
		this.tagName = name.toLowerCase();
	}

	@Override
	public boolean match(Matcher matcher) {

		if (matcher.context.getCurPointer().getTagName().equals(tagName)) {
			Element pointer = matcher.context.rollUp();
			if (pointer.getSibling() == null)
				matcher.next = pointer.getParent();
			else
				matcher.next = pointer.getSibling();

			return true;
		} else
			return false;
		
	}

	@Override
	public boolean apply(Matcher matcher) {
		matcher.applyResult.append("</");
		matcher.applyResult.append(this.tagName);
		matcher.applyResult.append('>');

		return true;
	}

}
